package com.gitee.kamismile.stone.basic.data.infrastructure.repository.r2Repository.sysDep.repository;

import com.gitee.kamismile.stone.basic.data.domain.sysDep.repository.entity.SysDep;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Mono;

import java.util.List;

public interface SysDepRepository extends R2dbcRepository<SysDep,Integer> {

  @Modifying
  @Query("UPDATE sys_dep AS sd" +
          " left join sys_dep as sdd on sdd.n_parent_id=sd.n_sys_dep_id" +
          " SET sd.s_islast = if(sdd.n_sys_dep_id is null,1,0)" +
          " WHERE sd.n_tenant_id = :nTenantId" +
          "  AND sd.n_sys_dep_id = :nSysDepId")
  Mono<Integer> modifyIslast(Integer nSysDepId, Integer nTenantId);

  }
